<template>
  <div id="menu">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="菜单名称">
        <el-input v-model="form.name" placeholder="菜单名称查询"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-plus" @click="dialogFormVisible = true">添加菜单</el-button>

        <el-dialog title="添加  菜单" :visible.sync="dialogFormVisible">
          <el-form :model="tableData">
            <el-form-item label="快速选择" :label-width="formLabelWidth" style="margin-bottom:20px;">
              <el-select v-model="tableData.sign" placeholder="请选择需要添加的路由权限">
                <el-option label="开发部" value="shanghai"></el-option>
                <el-option label="运营部" value="beijing"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="菜单名称" :label-width="formLabelWidth" style="margin-bottom:20px;">
              <el-input v-model="tableData.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="菜单标识" :label-width="formLabelWidth" style="margin-bottom:20px;">
              <el-input v-model="tableData.sign" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="菜单URL" :label-width="formLabelWidth" style="margin-bottom:20px;">
              <el-input v-model="tableData.address" autocomplete="off"></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
          </div>
        </el-dialog>

        <span style="margin-left:800px;">
          <el-button type="primary" icon="el-icon-search">查询</el-button>
          <el-button type="primary" icon="icon-zhongzhi">重置</el-button>
        </span>
      </el-form-item>
    </el-form>

    <el-table :data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)" border style="width: 100%">
      <el-table-column prop="id" label="id" width="180">
      </el-table-column>
      <el-table-column prop="name" label="菜单名称" width="180">
      </el-table-column>
      <el-table-column prop="sign" label="菜单表示">
      </el-table-column>
      <el-table-column prop="address" label="菜单URL">
      </el-table-column>
      <el-table-column prop="des" label="说明">
      </el-table-column>
      <el-table-column label="Action">
        <template slot-scope="scope">


          <el-button type="primary" plain @click="setInfo(scope.row)">编辑</el-button>
          <el-button type="danger" plain @click="dec">删除</el-button>
        </template>
       


      </el-table-column>
    </el-table>
     <el-dialog title="编辑  菜单" :visible.sync="dialogFormVisible">
          <el-form :model="form">
            <el-form-item label="菜单名称" :label-width="formLabelWidth" style="margin-bottom:20px;">
              <el-input v-model="form.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="菜单标识" :label-width="formLabelWidth" style="margin-bottom:20px;">
              <el-input v-model="form.sign" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="菜单URL" :label-width="formLabelWidth" style="margin-bottom:20px;">
              <el-input v-model="form.address" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="菜单描述" :label-width="formLabelWidth" style="margin-bottom:20px;">
              <el-input v-model="form.des" autocomplete="off"></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
          </div>
        </el-dialog>
    <el-pagination style="margin-left:820px;margin-top:20px;" @size-change="handleSizeChange"
      @current-change="handleCurrentChange" :page-sizes="[4,8]" :page-size="100"
      layout="total, sizes, prev, pager, next, jumper" :total="tableData.length">
    </el-pagination>
  </div>
</template>
<script>
  export default {
    name: 'menu',
    data() {
      return {
        form: {
          name: '',
          sign: '',
          address: '',
          des:''

        },
        dialogFormVisible: false,
        formLabelWidth: '120px',
        currentPage: 1, // 默认开始页面
        pagesize: 4,
        total: 0,
        tableData: [{
          id: '2016-05-02',
          name: '王小虎',
          sign: '上海市普陀区金沙江路 1518 弄',
          address: '上海市普陀区金沙江路 1518 弄',
          des: '上海市普陀区金沙江路 1518 弄'
        }, {
          id: '2016-05-04',
          name: '王小虎',
          sign: '上海市普陀区金沙江路 1517 弄',
          address: '上海市普陀区金沙江路 1517 弄',
          des: '上海市普陀区金沙江路 1517 弄'
        }, {
          id: '2016-05-01',
          name: '王小虎',
          sign: '上海市普陀区金沙江路 1519 弄',
          address: '上海市普陀区金沙江路 1519 弄',
          des: '上海市普陀区金沙江路 1519 弄'
        }, {
          id: '2016-05-03',
          name: '王小虎',
          sign: '上海市普陀区金沙江路 1516 弄',
          address: '上海市普陀区金沙江路 1516 弄',
          des: '上海市普陀区金沙江路 1516 弄'
        }, {
          id: '2016-05-03',
          name: '王小虎',
          sign: '上海市普陀区金沙江路 1516 弄',
          address: '上海市普陀区金沙江路 1516 弄',
          des: '上海市普陀区金沙江路 1516 弄'
        }]
      }
    },
    methods: {
      handleSizeChange(size) {
        console.log(`每页 ${size} 条`)
        this.pagesize = size
      },
      handleCurrentChange(currentPage) {
        this.currentPage = currentPage
        console.log(`当前页: ${currentPage}`)
      },
      dec() {
        this.$message('孩子不要删除啦！！！')
      },
      setInfo(info) {
        this.form = info;
        this.dialogFormVisible = true;
      },
    }
  }
</script>
<style scoped>
  .el-input {
    width: 200px;
  }
</style>